package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {

    @Autowired
    StudentService studentService;

    //分页查询
    @GetMapping
    public Result queryString(Integer page, Integer pageSize,
                              String name, String no,
                              Integer degree, Integer clazzId) {
        log.info("分页查询，参数：{},{},{},{},{},{}", page, pageSize, name, no, degree, clazzId);
        PageBean pageBean = studentService.queryString(page, pageSize, name, no, degree, clazzId);
        return Result.ok(pageBean);
    }

    //删除学员
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除学员ids:{}", ids);
        studentService.delete(ids);
        return Result.ok();
    }

    //添加学员
    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("添加学生student:{}", student);
        studentService.add(student);
        return Result.ok();
    }

    //根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据ID查询学员信息:{}", id);
        Student student = studentService.geById(id);
        return Result.ok(student);
    }

    //修改学员
    @PutMapping
    public Result updateById(@RequestBody Student student) {
        log.info("根据id修改学员信息:{}", student);
        studentService.updateById(student);
        return Result.ok();
    }

    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("违纪处理:{},{}",id,score);
        studentService.violation(id, score);
        return Result.ok();
    }
}
